#include "../../../common/data_es.hpp"
#include <gflags/gflags.h>

DEFINE_bool(run_mode, false, "程序的运行模式, false-调试; true-发布;");
DEFINE_string(log_file, "", "发布模式下, 用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下, 用于指定日志输出等级");  //trace default 0

DEFINE_string(es_host, "http://127.0.0.1:9200/", "es服务器url");
int main(int argc, char* argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    
    xchat::init_logger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    auto es_client = xchat::ESClientFactory::createClient({FLAGS_es_host});

    auto es_msg = std::make_shared<xchat::ESMessage>(es_client);

    //     bool ret = ESIndex(_es_client, "message")
    //             .append("user_id", "keyword", "standard", false)
    //             .append("message_id", "keyword", "standard", false)
    //             .append("create_time", "long", "standard", false)  //true 作为索引 用作搜索 false 不作为索引只供存储
    //             .append("chat_session_id", "keyword", "standard", true)
    //             .append("content", "text", "ik_max_word", true) //keyword，
    //es_msg->createIndex();
    // es_msg->appendData("用户ID1", "消息ID1", 1759221061 , "会话ID1", "hello");
    // es_msg->appendData("用户ID2", "消息ID2", 1759221062 , "会话ID1", "world");
    // es_msg->appendData("用户ID3", "消息ID3", 1759221063 , "会话ID2", "你好");
    // es_msg->appendData("用户ID4", "消息ID4", 1759221064 , "会话ID2", "世界");
    //es_msg->appendData("用户ID5", "消息ID5", 1759221065 , "会话ID2", "世界你好");


    auto res = es_msg->search("界你", "会话ID2");

    for(auto &u : res)
    {
        std::cout << "----------------" << std::endl;
        std::cout << "用户ID: " << u.user_id() << std::endl;
        std::cout << "手机号: " << u.message_id() << std::endl;
        std::cout << "用户名: " << u.session_id() << std::endl;
        std::cout << "用户描述: " << boost::posix_time::to_simple_string(u.create_time()) << std::endl;
        std::cout << "用户头像: " << u.content() << std::endl;
    }


    return 0;
}